import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:yyshort/common/model/useInfo_model.dart';

class AboutUsPage extends StatelessWidget {
  const AboutUsPage({super.key});

  // 打开链接的方法
  Future<void> _launchUrl(String url) async {
    final Uri uri = Uri.parse(url);
    if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
      Get.snackbar(
        '错误'.tr,
        '无法打开链接'.tr,
        snackPosition: SnackPosition.BOTTOM,
        backgroundColor: Colors.black87,
        colorText: Colors.white,
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    // 预构建内容，避免重复渲染导致的闪动
    final pageContent = Column(
      children: [
        // 应用信息区域
        Padding(
          padding: EdgeInsets.all(20.0),
          child: Column(
            children: [
              SizedBox(
                width: 80.w,
                height: 80.h,
                // color: Colors.blue,
                child: Image.asset("assets/images/yy_logo.png"),
              ),

              SizedBox(height: 16),
              Text(
                'YY Short',
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
              SizedBox(height: 8),
              Text(
                '${'版本'.tr} 1.1.0',
                style: TextStyle(fontSize: 16, color: Colors.white),
              ),
            ],
          ),
        ),

        const Divider(height: 1, color: Colors.white30),

        // 功能入口列表
        Expanded(
          child: ListView(
            children: [
              ListTile(
                title: Text('隐私协议'.tr, style: TextStyle(color: Colors.white)),
                trailing: const Icon(
                  Icons.arrow_forward_ios,
                  size: 18,
                  color: Colors.white54,
                ),
                onTap: () => _launchUrl(
                  'https://yy.yyshort.com/privacy_agreement?language=${UserInfo().language}',
                ),
                splashColor: Colors.white70,
              ),
              const Divider(height: 1, color: Colors.white30),
              ListTile(
                title: Text('用户政策'.tr, style: TextStyle(color: Colors.white)),
                trailing: const Icon(
                  Icons.arrow_forward_ios,
                  size: 18,
                  color: Colors.white54,
                ),
                onTap: () => _launchUrl(
                  'https://yy.yyshort.com/user_agreement?language=${UserInfo().language}',
                ),
                splashColor: Colors.white70,
              ),
            ],
          ),
        ),

        // 底部信息
        // Padding(
        //   padding: EdgeInsets.all(16.0),
        //   child: Text(
        //     // ignore: prefer_interpolation_to_compose_strings
        //     '© 2023 YYSHORT ' + '版权所有'.tr,
        //     style: TextStyle(fontSize: 14, color: Colors.white),
        //   ),
        // ),
      ],
    );

    return Scaffold(
      // 确保背景色与上一页面一致或平滑过渡
      backgroundColor: Colors.black87,
      appBar: AppBar(
        title: Text('关于我们'.tr, style: TextStyle(color: Colors.white)),
        centerTitle: true,
      ),
      // 预缓存页面背景，避免首次渲染空白
      body: Container(color: Colors.black87, child: pageContent),
    );
  }
}
